export default {
  data() {
    return {
      iapChannel: null,
      productId: 'your_product_id', // 替换为你的应用内购买项目ID
      orderNo: 'your_order_no', // 订单号
      quantity: 1, // 产品数量
    };
  },
  onLoad() {
    this.initPayment();
  },
  methods: {
    async initPayment() {
      try {
        // 获取支付通道
        await this.getIapChannels();
        // 初始化支付项目列表（获取订单信息）
        await this.requestIapOrder();
      } catch (error) {
        console.error('支付初始化失败:', error);
      }
    },
    getIapChannels() {
      plus.payment.getChannels((channels) => {
        for (let i = 0; i < channels.length; i++) {
          let channel = channels[i];
          if (channel.id === 'appleiap') {
            this.iapChannel = channel;
          }
        }
      }, (error) => {
        console.error('获取iap支付通道失败:', error.message);
      });
    },
    requestIapOrder() {
      if (this.iapChannel) {
        let ids = [this.productId];
        this.iapChannel.requestOrder(ids, (res) => {
          console.log('获取订单信息成功:', res);
        }, (error) => {
          console.error('获取订单信息失败:', error.code);
        });
      }
    },
    goApplePay() {
      if (this.iapChannel) {
        // 假设你有一个方法 payApply() 从            后端获取支付标识
        payApply().then((res) => {
          plus.payment.quantityrequest(this.iapChannel, {
            productid: this.productId,
:            username: res.data.out_trade_no,
 this.quantity,
          }, (result) => {
            console.log('支付结果:', result);
            this.handlePaymentResult(result);
          }, (error) => {
            console.error('支付失败:', error);
          });
        }).catch((err) => {
          console.error('获取支付标识失败:', err.message);
        });
      }
    },
    handlePaymentResult(result) {
      // 处理支付结果，例如更新订单状态、跳转到支付成功页面等
      if (result.status === 0) {
        console.log('支付成功');
        // 发送支付结果到服务器进行验证
        this.verifyPayment(result);
      } else {
        console.log('支付失败');
      }
    },
    verifyPayment(result) {
      // 假设你有一个方法 sendPaymentResultToServer() 将支付结果发送到服务器
      sendPaymentResultToServer(result).then((response) => {
        if (response.data.status === 'success') {
          console.log('支付验证成功');
        } else {
          console.log('支付验证失败');
        }
      }).catch((err) => {
        console.error('支付结果验证失败:', err.message);
      });
    },
  },
};

// {
//     "payment": {
//         "productid": "xdzd180",
//         "quantity": "1",
//         "username": "12345451212112"
//     },
//     "transactionDate": "2025-07-18 16:37:56",
//     "transactionIdentifier": "2000000964737972",
//     "transactionReceipt": "MIIUPQYJKoZIhvcNAQcCoIIULjCCFCoCAQExDzANBglghkgBZQMEAgEFADCCA3MGCSqGSIb3DQEHAaCCA2QEggNgMYIDXDAKAgEIAgEBBAIWADAKAgEUAgEBBAIMADALAgEBAgEBBAMCAQAwCwIBCwIBAQQDAgEAMAsCAQ8CAQEEAwIBADALAgEQAgEBBAMCAQAwCwIBGQIBAQQDAgEDMAwCAQoCAQEEBBYCNCswDAIBDgIBAQQEAgIAnzANAgEDAgEBBAUMAzE0MzANAgENAgEBBAUCAwJzxzANAgETAgEBBAUMAzEuMDAOAgEJAgEBBAYCBFAzMDUwGAIBAgIBAQQQDA5jbi5nYW1lcGFydG5lcjAYAgEEAgECBBDfHH5UcJp8SEbRHbGhBk/iMBsCAQACAQEEEwwRUHJvZHVjdGlvblNhbmRib3gwHAIBBQIBAQQUzOVBHfMGYY64EfUxcGXOTjm0OmMwHgIBDAIBAQQWFhQyMDI1LTA3LTE4VDA4OjM3OjU2WjAeAgESAgEBBBYWFDIwMTMtMDgtMDFUMDc6MDA6MDBaMD4CAQcCAQEENmS2Rf8Vas5ehL3+kPQVeMF7vZEGtZWPEoEWq2pk0tSMOdnQdf+ABsz5tqVLun6EI7utRMfNhTBbAgEGAgEBBFOtRSf3QcNkFfUT1uFuBVMcPm/4r0EIOXjkZgWQtInIbNoH/ZStwDuU+n3L6qEGloxxfGXs2OelWN453ElMASfrqIq5KJG/Pm2vhfpIa+j21DcKcjCCAVoCARECAQEEggFQMYIBTDALAgIGrAIBAQQCFgAwCwICBq0CAQEEAgwAMAsCAgawAgEBBAIWADALAgIGsgIBAQQCDAAwCwICBrMCAQEEAgwAMAsCAga0AgEBBAIMADALAgIGtQIBAQQCDAAwCwICBrYCAQEEAgwAMAwCAgalAgEBBAMCAQEwDAICBqsCAQEEAwIBATAMAgIGrgIBAQQDAgEAMAwCAgavAgEBBAMCAQA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O0FwcGxlIFdvcmxkd2lkZSBEZXZlbG9wZXIgUmVsYXRpb25zIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MQswCQYDVQQLDAJHNTETMBEGA1UECgwKQXBwbGUgSW5jLjELMAkGA1UEBhMCVVMCEH05IAlOvvP478psEOqOQwMwDQYJYIZIAWUDBAIBBQAwDQYJKoZIhvcNAQEBBQAEggEAS3aKE9J+zuyr1igKbuGwqcU1A07Igvmg5avnnJu5mJ8OgK8S76Trt02SOaMIzRmv37niHBeg4GG4mff1wGnFvQ9tVCb25P3PZdkNDfVRF4ZEXPveKIFQAWgC0s7FeVm9/yX49+OCd9yVXljrAm/VLjNEF5pEfVgYoQgbl6n78a4A1QIxD5ltMKX9ZxlPDLgTkLoliFBKudCcAdWSOw4cmwOcH7XNu0qHpZCaL7rPH59VbM1Uo9rrnkdqzTrIqhvy8QE+WSJ9xi1E0MJk1xpiP5NX3hoZ2G6xgE0QeK+MAoEnC1vWQSVmGwRnc1OtTApvBXhfR/2OZyYaOYRJY06G0w==",
//     "transactionState": "1"
// }
// 嗒币1680个 - xdzd168  - ¥168.00
// 嗒币180个 - xdzd180  - ¥18.00
// 嗒币1980个 - xdzd198 - 	¥198.00
// 嗒币60个 - xdzd123 - ¥18.00
// 嗒币680个 - xdzd680 - ¥68.00
// 嗒币980个 - xdzd980 - ¥98.00

// https://mng-da.yueyangtech.com.cn/
// admin
// XiaoDa@123!